#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"

trigger-builder-dockerfile-builder-release() {
  declare desc="builder-dockerfile builder-release plugin trigger"
  declare trigger="builder-release"
  declare BUILDER_TYPE="$1" APP="$2" IMAGE_TAG="$3"

  if [[ "$BUILDER_TYPE" != "dockerfile" ]]; then
    return
  fi

  # buildstep plugins don't necessarily make sense for dockerfiles. call the new breed!!!
  plugn trigger pre-release-dockerfile "$APP" "$IMAGE_TAG"

  local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
  echo "FROM $IMAGE" | suppress_output "$DOCKER_BIN" image build --label=com.dokku.image-stage=release -t "$IMAGE" -
  plugn trigger post-release-dockerfile "$APP" "$IMAGE_TAG"
}

trigger-builder-dockerfile-builder-release "$@"
